import javafx.scene.control.SplitPane;

import java.util.List;


public class StatementGenerator {
    public static String DIVIDE = "\n-----------------------------------";
    private static final String FOOTER = "\n===================================";

    public static String PrintStatement(PromotionOrder promotionOrder) {
    StringBuilder result = new StringBuilder();
    result.append("============= Order details =============");
    result.append(formatOrderItems(promotionOrder.orderItems));
    result.append(DIVIDE);
    result.append(promotionOrder.bestPromotionResult.formatStatement());
    result.append(formatTotalAmount(promotionOrder.amount));
    result.append(FOOTER);
    
    return result.toString();
    }

    private static String formatTotalAmount(Double amount) {
        return String.format("\nTotal：%.0f yuan",amount);
    }

    private static String formatOrderItems(List<OrderItem> orderItems) {
        return orderItems.stream().map(StatementGenerator::formatOrderItem)
                .reduce((pre, cur) -> pre + cur)
                .orElse("");
    }

    private static String formatOrderItem(OrderItem orderItem) {
        return String.format("\n%s x %d = %.0f yuan",orderItem.getName(),
                orderItem.getCount(),orderItem.getAmount());
    }
}
